package weaver.jobs.xfjt.duss.cronjob;

import weaver.common.DateUtil;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.interfaces.schedule.BaseCronJob;
import weaver.jobs.xfjt.duss.utils.XfjtUtil;

import java.util.HashMap;
import java.util.Map;

/**
 * @Title: ecology
 * @Company: 泛微软件
 * @author: weaver.Dusongsong
 * @version: 1.0
 * @CreateDate: 2022-08-30
 * @Description: 周期督查督办台账按照周期模式触发督办反馈流程
 * @ModifyLog:
 **/

public class WeCycleGovernCronJob extends BaseCronJob {

    @Override
    public void execute() {
        BaseBean baseBean = new BaseBean();
        RecordSet rs = new RecordSet();
        try {
            String currentDate = DateUtil.getCurrentDate();
            baseBean.writeLog( ">>>>>>WeCycleGovernCronJob>>>>currentDate" + currentDate );
            String sql = "select * from uf_zqdc where dczt=0 and  dcksrq<='" + currentDate + "' and dcjsrq >='" + currentDate + "'";
            rs.executeQuery( sql );
            String [] columnName = rs.getColumnName();
            while (rs.next()) {
                Map<String, String> requestMainMap = new HashMap<>();
                //数据id
                String dataid = Util.null2String( rs.getString( "id" ) );
                //督查重复模式:0-按天重复;1-按周重复;2-按月重复
                String dczfms = Util.null2String( rs.getString( "dczfms" ) );
                //每次反馈期限（天）
                int mcfkqxt = Util.getIntValue( rs.getString( "mcfkqxt" ) );
                String lcck = Util.null2String( rs.getString( "lcck" ) );
                String xywcfkrq = DateUtil.addDate(DateUtil.addDate(currentDate,mcfkqxt),-1);
                String strs = XfjtUtil.getFieldName("-101");
                for (String column: columnName) {
                    String columnValue = Util.null2String( rs.getString( column ) );
                    if (!"".equals( columnValue ) && strs.contains( column )) {
                        requestMainMap.put( column, columnValue );
                    }
                }
                requestMainMap.put("fkfqrq", currentDate );
                requestMainMap.put("sjid", dataid );
                requestMainMap.put("gllc", lcck );
                requestMainMap.put("xywcfkrq", xywcfkrq );
                switch (dczfms) {
                    case "0":
                        XfjtUtil.runRntervalDay(currentDate,requestMainMap,dataid );
                        break;
                    case "1":
                        XfjtUtil.runRntervalWeek( currentDate,requestMainMap,dataid );
                        break;
                    case "2":
                        XfjtUtil.runRntervalMonth( currentDate,requestMainMap,dataid );
                        break;
                    default:
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}

